import '@/styles';
//注册图标精灵
import 'virtual:svg-icons-register';
import App from './app.vue';
import { initPackages } from './init-packages';
import { createApp } from 'vue';
import { initAppConfigStore } from '@/logics/init-app-config';
import { router, setupRouter } from '@/router';
import { setupRouterGuard } from '@/router/guard';
import { pinia, registerGlobalComponents, registerThirdComp } from '@/internal';
import { setupI18n } from '@pkg/locale';
import { registerGlobalDirective } from '@pkg/directives';
import { useUserStore } from '@/store/user';
import { useSso } from '@/hooks/web/useSso';
const bootstrap = async () => {
  const app:any = createApp(App);
  app.use(pinia);
  //需要注意调用时机
  await initPackages();
  //初始化内部系统配置
  initAppConfigStore();
  //注册全局组件
  registerGlobalComponents(app);

  //CAS单点登录
  await useSso().ssoLogin();
  //注册第三方组件
  await registerThirdComp(app);
  // 多语言配置,异步情况：可以从服务端获取语言文件
  await setupI18n(app);
  //路由配置
  setupRouter(app);
  //路由器防护
  setupRouterGuard(router);
  //注册全局指令
  registerGlobalDirective(app);
  await router.isReady();
  app.mount('#app');
  // 在关闭 MOCK 的时候, Tree Shaking `mockjs` 依赖
  if (__VITE_USE_MOCK__) {
    import('../mock/_mock-server').then(({ setupProdMockServer }) => setupProdMockServer());
  }
};

bootstrap().then(() => {
  const userStore = useUserStore();
  userStore.initDictAction().then(() => {
    console.info('字典初始化成功');
  });
});
